package com.huawei123.hasee.cniao5store.adapter.top;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.huawei123.hasee.cniao5store.R;
import com.huawei123.hasee.cniao5store.bean.TopBean;
import com.zhxu.recyclerview.App;

import java.util.List;

/**
 * 项目名称：Cniao5Store
 * 类描述：
 * 创建人：luohao
 * 创建时间：2018/2/5 18:32
 * 修改人：luohao
 * 修改时间：2018/2/5 18:32
 * 修改备注：
 */

public class TopSubAdapter extends BaseAdapter {

    private final Context context;
    private final List<TopBean.TopTopBean> topTopBeans;

    public TopSubAdapter(Context context, List<TopBean.TopTopBean> topTopBeans) {
        this.context = context;
        this.topTopBeans = topTopBeans;
    }

    @Override
    public int getCount() {
        return topTopBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return topTopBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TopBean.TopTopBean topTopBean = topTopBeans.get(position);
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.appdetail_subcat_title, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(App.getContext()).load(topTopBean.getIconUrl()).into(viewHolder.mIV_appicon);
        viewHolder.mTV_ItemTitle.setText(topTopBean.getName());
        return convertView;
    }

    class ViewHolder {

        private ImageView mIV_appicon;
        private TextView mTV_ItemTitle;

        public ViewHolder(View convertView) {
            mIV_appicon = (ImageView) convertView.findViewById(R.id.mIV_appicon);
            mTV_ItemTitle = (TextView) convertView.findViewById(R.id.mTV_ItemTitle);
        }
    }
}
